﻿FlyTalk.views.QuestionForm = Ext.extend(Ext.form.FormPanel, {
	bodyStyle: 'background: #2f2f2e',
	
	scroll: true,
    initComponent: function () {
		
		// back button on toolbar
		this.backButton = new Ext.Button({
			text: 'Back',
			ui: 'back',
			handler: this.backButtonTap,
			scope: this
		});
		
		// save button on toolbar
		this.saveButton = new Ext.Button({
			text: 'Send',
			ui: 'action',
			style: 'background: #f7941d',
			handler: this.saveButtonTap,
			scope: this
		});
		
		// top tool bar
		this.toolbar = new Ext.Toolbar({
			title: 'Ask',
			
			items:[
				this.backButton,
				{ xtype: 'spacer' },
				this.saveButton,	
			]
		});
	
        this.dockedItems = [this.toolbar];
	
        FlyTalk.views.QuestionForm.superclass.initComponent.call(this);
		
    },	

    backButtonTap: function () {
		this.items.getAt(2).value="";

		var next = FlyTalk.views.TalkView.tweetToolbar.title; // see which page talk is on right now
		Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'openNext',
            next: next,
        });
		/*
		if(next == 'Search'){
			var next = FlyTalk.views.TalkView.tweetToolbar.title; // see which page talk is on right now
	        Ext.dispatch({
	        	controller: FlyTalk.controllers.ftController,
	        	action: 'openSearch',
	        });
		}else{
			Ext.dispatch({
	            controller: FlyTalk.controllers.ftController,
	            action: 'openNext',
	            next: next,
	        });
		}*/
    },
    
	saveButtonTap: function () {
		 var comment = Ext.getCmp('comment').getValue();
		 if(comment.length > 140){
			 alert("Comment ("+comment.length+" characters) exceeds the 140 character limit.");
		 }else{
			 var user = Ext.getCmp('selectUser').getValue();	
			 this.reset();
			 if(this.toolbar.title == 'Reply'){
				// var tid = FlyTalk.views.ColumnView.MixedStore.getAt(this.items.getAt(1).label).data;
				 var ind = this.items.getAt(3).label;
				 Ext.dispatch({
			            controller: FlyTalk.controllers.dbController,
			            action: 'saveReply',
			            text: comment,
			            index: ind,
			            uid: user,
			     });
			 }else {
				 if(this.toolbar.title == 'Ask'){
					 Ext.dispatch({
				            controller: FlyTalk.controllers.dbController,
				            action: 'saveQuestion',
				            text: comment, 
				            uid: user,
				     });
				 }else{
					 Ext.dispatch({
				            controller: FlyTalk.controllers.dbController,
				            action: 'saveComment',
				            text: comment,    
				            uid: user,
				     });
				 }
			 }
		 }
    },
    
	items: [
	{ // select a user (researcher mode only!) - THIS FIELD HAS TO BE THE FIRST. DO NOT CHANGE!
	    xtype: 'selectfield',
	    name: 'user',
	    id: 'selectUser',
	    label: 'select user',
	    labelWidth: 300,
	    labelAlign: 'top',
	    options: [
{text: 'AnaD',  value: '3'},
{text: 'TAP Airline',  value: '1'},
{text: 'Airport',  value: '2'},
{text: 'Jessica', value: '4'},
{text: 'JoaoDias',  value: '5'},
{text: 'FlyTalk', value: '6'},
{text: 'MariaFreitas',  value: '7'},
{text: 'TruthSlinger',  value: '8'},
{text: 'PradaLvr',  value: '9'},
{text: 'CrazyCanuck', value: '10'},
{text: 'Sugarlicious',  value: '11'},
{text: 'GiveMeKittens',  value: '12'},
{text: 'CRonaldo',  value: '13'},
{text: 'ProfJoe', value: '14'},
{text: 'laItaliana',  value: '15'},
{text: 'Tiagossss', value: '16'},
{text: 'payday',  value: '17'},
{text: 'AmeliaBedelia',  value: '18'},
{text: 'Juliana',  value: '19'},
{text: 'MarisaManuel', value: '20'},
{text: 'VSarmento',  value: '21'},
{text: 'ProperGent', value: '22'},
{text: 'Perfumeire', value: '23'},
{text: 'Lacoste',  value: '24'},
{text: 'Levi', value: '25'},
	    ]
	},      {
    	xtype: 'fieldset',
		title: 'Comments',
		style: 'margin-bottom: 1em; margin-top: 0em;',
    },  
	{  // textarea for msg
		xtype: 'textareafield',
		id:'comment',
        name: 'title',
      //  label: 'Comment: ',
	//	labelWidth: 300,
		//labelAlign: 'top',
		height: 100,
        required: true,
					
    },{
    	//add hidden button to pass values
    	xtype: 'textareafield',
        label: 'T',
        required: false,
        hidden: true,
    },
    {
    	xtype: 'fieldset',
		title: 'Tag staff in the feed',
		style: 'margin-bottom: 0em',
    },
    {// tag someone 
		xtype: 'fieldset',
			defaults: {
				xtype: 'radiofield',
				labelwidth: '70%',
			},
			items: [{
				name: 'airline',
				value: 'airline',
				label: 'TAP',
			},{
				name: 'official',
				value: 'official',
				label: 'Official',
			}]
	},
    {
    	xtype: 'fieldset',
		title: 'Attach a location',
		style: 'margin-bottom: 1em',
    },
	{
		xtype:'button',
		text: 'Add current location',
		style: 'margin: .5em;',
		ui: 'action'

	},{
		xtype:'button',
		text: 'Add location from map',
		style: 'margin: .5em',
		ui: 'action'
	},
    {
    	xtype: 'fieldset',
		title: 'Add a photo',
		style: 'margin-bottom: 1em',
    },
	{
		xtype:'button',
		text: 'Use photo from camera',
		style: 'margin: .5em',
		ui: 'action'
	},{
		xtype:'button',
		text: 'Upload a photo',
		style: 'margin: .5em',
		ui: 'action'
	},
	]	
});

